<template>
  <div style="width: 100%">
    <div id="deawer">
      <v-tableTitle :btnConfig="btnConfig"
                    @cancel="cancel"
                    @save="save"
                    @addccmirroring="addccmirroring"
                    @writeactulstock="writeactulstock"
                    @writestocknull="writestocknull"
                    @writestatusnew="writestatusnew"
                    @writestatusfinish="writestatusfinish"
                    @closeparenttask="closeparenttask"
                    @newSave="newSave"></v-tableTitle>
      <div class="detailBox">
        <v-detail ref="detail"></v-detail>
      </div>
      <div class="detailListBox"
           v-if="!newFlag">
        <v-detailList ref="detailList"></v-detailList>
      </div>
    </div>
  </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import config from "../Config"
import tableTitle from "commons/TableTitle";
import detail from "../details/Detail"
import detailList from "../detailsList/DetailList"

export default {
  name: "",
  mixins: [baseMixin, skipMixin, config],
  data () {
    return {
      flag: false,
      newFlag: false,
      routeData: {},
      screenid: ""
    };
  },
  computed: {
    btnConfig () {
      if (this.newFlag) {
        return [
          { label: this.$t('common.save'), certigier: this.saveStatus||!this.btnPermNameList.includes('WM06040206'), invalid: "save" },
          { label: this.$t('work.createccmirroring'), certigier: this.saveStatus||!this.btnPermNameList.includes('WM06040221'), invalid: "newSave" },
          { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM06040214'), invalid: "cancel" },
        ]
      } else {
        return [
          { label: this.$t('common.save'), certigier: this.saveStatus||!this.btnPermNameList.includes('WM06040206'), invalid: "save" },
          {
            label: this.$t('out.action'), type: "more", certigier: !this.btnPermNameList.includes('WM06040207'), invalid: "save", btnConfig: [
              { label: this.$t('work.addccmirroring'), certigier: this.addCcmirroringStatus||!this.btnPermNameList.includes('WM06040208'), invalid: "addccmirroring" },
              { label: this.$t('work.writeactulstock'), certigier: this.writeActulStockStatus||!this.btnPermNameList.includes('WM06040209'), invalid: "writeactulstock" },
              { label: this.$t('work.writestocknull'), certigier: this.writesStockNullStatus||!this.btnPermNameList.includes('WM06040210'), invalid: "writestocknull" },
              { label: this.$t('work.writestatusnew'), certigier: this.writesStatusNewStatus||!this.btnPermNameList.includes('WM06040211'), invalid: "writestatusnew" },
              {
                label: this.$t('work.writestatusfinish'),
                certigier: this.writeStatusFinishStatus||!this.btnPermNameList.includes('WM06040212'),
                invalid: "writestatusfinish"
              },
              { label: this.$t('work.closeparenttask'), certigier: this.closeParentTaskStatus||!this.btnPermNameList.includes('WM06040213'), invalid: "closeparenttask" },
            ]
          },
          { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM06040214'), invalid: "cancel" },
        ]
      }

    }
  },
  created () {
  },
  methods: {
    addccmirroring () {
      this.$router.push({ name: "ccexception" })
    },
    async writeactulstock () {
      try {
        let res = await this.$api.get(`/actionCCMirringdetail/WRITEACTULSTOCK/${this.routeData.subkey}`);
        
          this.$message.success(res.returnMgr)
          this.$refs.detailList.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async writestocknull () {
      try {
        let res = await this.$api.get(`/actionCCMirringdetail/WRITESTOCKNULL/${this.routeData.subkey}`);
        
          this.$message.success(res.returnMgr)
          this.$refs.detailList.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async writestatusnew () {
      try {
        let res = await this.$api.get(`/actionCCMirringdetail/WRITESTATUSNEW/${this.routeData.subkey}`);
        
          this.$message.success(res.returnMgr)
          this.$refs.detailList.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async writestatusfinish () {
      try {
        let res = await this.$api.get(`/actionCCMirringdetail/WRITESTATUSFINISH/${this.routeData.subkey}`);
        
          this.$message.success(res.returnMgr)
          this.$refs.detailList.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async closeparenttask () {
      try {
        let res = await this.$api.get(`/genenalNexttask/${this.routeData.status}/${this.routeData.subkey}`);
        
          this.$message.success(res.returnMgr)
          this.$refs.detailList.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //保存按钮
    async save () {
      let flag = this.$refs.detail.$children[0].$refs.input.submitForm("from");
      if (!flag) {
        return;
      }
      let detail = this.$refs.detail.detailData;
      try {
        let response = await this.$api.get("/getUUID");
          this.screenid = response.bean;
          detail = {
            ...detail,
            screenid: response.bean,
          }
          try {
            let res = await this.$api.post('/insertRtx_ccproduct', detail);
            
              this.$message.success(res.returnMgr);
              this.flag = true;
          } catch (e) {
            this.$message.error(e)
          }

      } catch (e) {
        this.$message.error(e);
      }


    },
    //生成镜像
    async newSave () {
      if (this.screenid == "") {
        this.$message.error(this.$t('msg.msg71'));
        return;
      }
      let detail = this.$refs.detail.detailData;
      detail.screenid = this.screenid;
      try {
        let res = await this.$api.post(`cc_genenaltask`, detail);
        
          this.$message.success(res.returnMgr);
          this.cancel();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //弹框取消
    cancel () {
      this.$router.push({ name: "ccmirroring" });
    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.routeData = data.routeData;
      this.newFlag = data.newFlag;
    } else {
      this.routeData = this.$store.state.routeData;
      this.newFlag = this.$store.state.newFlag;
    }

  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-detail": detail,
    "v-detailList": detailList,
  }
}
</script>

<style scoped>
</style>
